package com.airsystem.pos.bengkel.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.airsystem.pos.bengkel.util.Preconditions;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */

@Entity
@Table(name = "tbl_jenis_sparepart")
public class JenisSparepart implements Serializable {

	@Transient
	public static final String ALIAS = "jenis_sparepart";

	@Transient
	private int choice;

	@Id
	@GeneratedValue
	private Long id;

	private String nama;

	@OneToMany(mappedBy = "jenis_sparepart", fetch = FetchType.LAZY)
	private Set<DetailSparepart> jenis_detail_sparepart = new HashSet<DetailSparepart>(0);

	public String getSearchColumn() {
		StringBuffer sb = new StringBuffer();

		switch (choice) {
		case 0:
			return sb.append(JenisSparepart.ALIAS).append(".nama").toString();

		default:
			return sb.append(JenisSparepart.ALIAS).append(".nama").toString();
		}
	}

	public String getSearchKeyword() {
		switch (choice) {
		case 0:
			return getNama();

		default:
			return "";
		}
	}

	public int getChoice() {
		return choice;
	}

	public void setChoice(int choice) {
		this.choice = choice;
	}

	public String getId_s() {
		Preconditions.checkNotNull(id);

		return String.valueOf(id);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

	public Set<DetailSparepart> getJenis_detail_sparepart() {
		return jenis_detail_sparepart;
	}

	public void setJenis_detail_sparepart(Set<DetailSparepart> jenis_detail_sparepart) {
		this.jenis_detail_sparepart = jenis_detail_sparepart;
	}
}